// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "custom/menu"
{
Properties
{
    [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
	_Color ("Tint", Color) = (1,1,1,1)
	_Stencil ("Stencil Ref", Float) = 0
	_StartRandian ("Start Randian",Float) =-1.5707963267948966192313216916398
	_EndRandian ("End Randian",Float) =1.5707963267948966192313216916398
	_CenterV ("CenterV",Float) =0.5
	_MinU ("MinU",Float) =0
	_MaxU ("MaxU",Float) =1
	_AlphaAreaWidth ("MaxU",Float) = 0.4
}

SubShader
{
    Tags
    { 
        "Queue"="Transparent" 
        "IgnoreProjector"="True" 
        "RenderType"="Transparent" 
        "PreviewType"="Plane"
        "CanUseSpriteAtlas"="True"
    }
	Stencil {
        Ref  [_Stencil]
        Comp Equal
        Pass replace
		
        ZFail decrWrap
    }
    Cull Off
    Lighting Off
    ZWrite Off
    Fog { Mode Off }
    Blend One OneMinusSrcAlpha

    Pass
    {
    CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #pragma multi_compile DUMMY PIXELSNAP_ON
        #include "UnityCG.cginc"

        struct appdata_t
        {
            float4 vertex   : POSITION;
			float4 color    : COLOR;
            float2 texcoord : TEXCOORD0;
        };

        struct v2f
        {
            float4 vertex   : SV_POSITION;
			fixed4 color    : COLOR;
            half2 texcoord  : TEXCOORD0;
        };

		fixed4 _Color;
        v2f vert(appdata_t IN)
        {
            v2f OUT;
            OUT.vertex = UnityObjectToClipPos(IN.vertex);
            OUT.texcoord = IN.texcoord;
			OUT.color = IN.color * _Color;
            return OUT;
        }

        sampler2D _MainTex;
		float _StartRandian;
		float _EndRandian;
		float _CenterU;
		float _CenterV;
		float _MinU;
		float _MaxU;
		float _AlphaAreaWidth;
        fixed4 frag(v2f IN) : SV_Target
        {
			float pi = 3.141526f;
			float dx = IN.texcoord.x - 0.5f;
			float dy = IN.texcoord.y - 0.5f;
			float adx = abs(dx);
			float ady = abs(dy);
			
			float currentRandian = atan2(dy, dx);
			
			float ds = currentRandian - _StartRandian;
			float de = _EndRandian - currentRandian;
            if(ds >= 0 && de >= 0)
			{
				float a1 = min(ds, de) / _AlphaAreaWidth;
				a1= min(a1, 1);
				
				float tx = clamp(sqrt((pow(adx, 2) + pow(ady, 2)) / pow(0.5, 2)), 0, 1);
				tx = tx * (_MaxU - _MinU) + _MinU;
				
				IN.texcoord.x = tx;
				IN.texcoord.y = _CenterV;
				
				fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
				c.a *= a1;
				c.rgb *= c.a;
				
				return c;
			}
			else
			{
				return fixed4(0,0,0,0);
			}
        }
    ENDCG
    }
}
}